<template>
  <h1>员工列表综合练习</h1>
  <el-menu >
    <el-form style="width: 50%;margin: 0 auto" label-width="80">
      <el-form-item label="姓名">
        <el-input v-model="emp.name" placeholder="请输入员工姓名"></el-input>
      </el-form-item>
      <el-form-item label="工资">
        <el-input v-model="emp.salary" placeholder="请输入员工工资"></el-input>
      </el-form-item>
      <el-form-item label="职位">
        <el-input v-model="emp.job" placeholder="请输入员工职位"></el-input>
      </el-form-item>
    </el-form>
  </el-menu>
  <el-button type="success" @click="f()">提交</el-button>
  <el-table :data="emps" style="width: 50%;margin: 0 auto">
    <el-table-column type="index" label="编号" width="80" align="center"></el-table-column>
    <el-table-column prop="name" label="姓名" align="center"></el-table-column>
    <el-table-column prop="salary" label="工资" align="center"></el-table-column>
    <el-table-column prop="job" label="职位" align="center"></el-table-column>
    <el-table-column fixed="right" label="操作" align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
  import {ref} from "vue";
  import {ElMessage} from "element-plus";
  const emp = ref({name: '', salary: '', job: ''})
  const emps = ref([])
  const f = () => {
    if(emp.value.name=='' || emp.value.salary=='' || emp.value.job==''){
      ElMessage.error('请输入完整信息')
      return;
    }
    emps.value.push(emp.value)
    emp.value = {}
    console.log(emps.value)
  }
  const del = (index,emp) => {
    if (confirm('确认删除'+emp.name+'吗')) {
      emps.value.splice(index, 1);
      ElMessage.success(emp.name+'删除成功')
    }
  }
</script>
<style scoped>
</style>